package com.one.efaimaly.order.model;

import com.one.common.common.order.MaterialItem;
import com.one.common.model.http.NetConstant;
import com.one.common.model.http.base.BaseModel;
import com.one.common.model.http.callback.ObserverOnResultListener;
import com.one.common.utils.StringUtils;
import com.one.common.view.base.BaseActivity;
import com.one.efaimaly.order.model.item.OrderDetailItem;

import java.util.List;
import java.util.Map;

/**
 * author ：zhulunjun
 * email  ：zhulunjun@qq.com
 * date   ：2018/8/8 下午10:17
 * description ：
 **/
public class OrderModel extends BaseModel<OrderApi> {
    public OrderModel(BaseActivity mActivity) {
        super(OrderApi.class, mActivity, NetConstant.APP_HOST_WORKER);
    }

    /**
     * 获取订单详情
     */
    public void getOrderDetail(String orderId, ObserverOnResultListener<OrderDetailItem> listener) {
        Map<String, String> params = getParams();
        params.put("order_id", orderId);
        handleOnResultObserver(mApiService.getOrderDetail(params), listener);
    }

    /**
     * 取消订单
     */
    public void cancel(String orderId, ObserverOnResultListener<String> listener) {
        Map<String, String> params = getParams();
        params.put("order_id", orderId);
        handleOnResultObserver(mApiService.cancel(params), listener);
    }

    /**
     * 添加材料
     */
    public void addMaterial(String orderId, String json, ObserverOnResultListener<String> listener) {
        Map<String, String> params = getParams();
        params.put("order_id", orderId);
        params.put("json", json);
        handleOnResultObserver(mApiService.addMaterial(params), listener);
    }

    /**
     * 获取材料
     */
    public void getMaterial(String page,String filter, ObserverOnResultListener<List<MaterialItem>> listener) {
        Map<String, String> params = getParams();
        params.put("page", page);
        if(StringUtils.isNotBlank(filter)) {
            params.put("material_name", filter);
        }
        handleOnResultObserver(mApiService.getMaterial(params), listener);
    }

    /**
     * 上传维修图片
     */
    public void uploadImg(String orderId, String img1,String img2, ObserverOnResultListener<String> listener) {
        Map<String, String> params = getParams();
        params.put("order_id", orderId);
        params.put("order_maintail_imgs1",img1);
        params.put("order_maintail_imgs2",img2);
        handleOnResultObserver(mApiService.uploadImg(params), listener);
    }

    /**
     * 上传维修图片
     */
    public void addRemark(String orderId, String remark, ObserverOnResultListener<String> listener) {
        Map<String, String> params = getParams();
        params.put("order_id", orderId);
        params.put("remark",remark);
        handleOnResultObserver(mApiService.addRemark(params), listener);
    }

}
